In [142]:
%load_ext autoreload
%autoreload 2
from pipeline import get_maps
from helpers import load_image, load_image2
import matplotlib.pyplot as plt
#%autoreload 2
%matplotlib inline

#Datastructure
from collections import OrderedDict


DATA_PATH = '../data/'
The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload
In [143]:
def show_maps(image1_path, image2_path, K, square=True):

    if(square):
        img_content = load_image(DATA_PATH + image1_path)
        img_context = load_image(DATA_PATH + image2_path)
    else:
        img_content = load_image2(DATA_PATH + image1_path, width=224)
        img_context = load_image2(DATA_PATH + image2_path, width=224)
    
    dicto = get_maps(img_content, img_context, K)
    
    plt.figure(figsize=(15, 10))
    plt.subplot(2, 2, 1)
    plt.imshow(img_content)

    plt.subplot(2, 2, 2)
    plt.imshow(img_context)
    
    plt.gcf().text(0.05, 0.7, "Original ", fontsize=25)
    
    for key, values in dicto.items():

        Ws, Hs = values
        
    
        for i in range(0,K):

            plt.figure(figsize=(15, 10))
            plt.gcf().text(0.05, 0.7, "K = " + str(i+1), fontsize=30)
            plt.gcf().text(0.885, 0.7, key.replace('conv',''), fontsize=30)

            plt.subplot(2, 2, 1)
            plt.imshow(Ws[:,:,i])
            #plt.colorbar()

            plt.subplot(2, 2, 2)
            plt.imshow(Hs[i])
            #plt.colorbar()

            plt.show()

Check effect of layers on face images with K = 5

Conv2 and Conv3

In [75]:
image1_path='../data/face/1.jpg'
image2_path='../data/face/2.jpg'
K = 10

show_maps(image1_path, image2_path, K)
npy file loaded
build model started
build model finished: 0s

Conv4 and Conv5

In [72]:
show_maps(image1_path, image2_path, K)
npy file loaded
build model started
build model finished: 0s

Check for layer 3_3, 3_4, 4_3 and 4,4 how K in [5, 10, 15, 20, 25] changes the outcome

In [88]:
[show_maps(image1_path, image2_path, K) for K in map(lambda x: x*5, list(range(1,6)))]
npy file loaded
build model started
build model finished: 0s
npy file loaded
build model started
build model finished: 0s
npy file loaded
build model started
build model finished: 0s
npy file loaded
build model started
build model finished: 0s
npy file loaded
build model started
build model finished: 0s
Out[88]:
[None, None, None, None, None]

Let's fix K = 20 and check other faces

In [112]:
image1_path='../data/face/1.jpg'
image2_path='../data/face/2.jpg'
image3_path='../data/face/3.jpg'
image4_path='../data/face/4.jpg'
image5_path='../data/face/5.jpg'

#let's check two males
show_maps(image3_path, image5_path, 20)

Let's check two guys with glasses

In [113]:
show_maps(image4_path, image5_path, 20)

what about a guy and a girl

In [114]:
show_maps(image2_path, image5_path, 20)

What about paintings

In [116]:
image_path_paint1 = '../data/face_paintings/4.jpg'
show_maps(image3_path, image_path_paint1, 20)
In [118]:
image_path_paint_face_7 = '../data/face_paintings/7.jpg'
show_maps(image2_path, image_path_paint_face_7, 20)

Building

In [120]:
show_maps('../data/city/1.jpg', '../data/city/7.jpg', 20)
In [121]:
show_maps('../data/city/2.jpg', '../data/city/4.jpg', 20)
In [122]:
show_maps('../data/city/5.jpg', '../data/city/7.jpg', 20)
#no water map because of light reflect maybe?

Indoor

In [123]:
show_maps('../data/indoor/1.jpg', '../data/indoor/2.jpg', 20)
In [124]:
show_maps('../data/indoor/4.jpg', '../data/indoor/6.jpg', 20)
# K = 10 is interesting

landscape

In [147]:
show_maps('../data/landscape/4.jpg', '../data/landscape/5.jpg', 20, True)
In [148]:
show_maps('../data/landscape/3.jpg', '../data/landscape/4.jpg', 20, True)
In [149]:
show_maps('../data/landscape/1.jpg', '../data/landscape/5.jpg', 20, True)
# this setup doesn't work so well for landscape i think

Landscape + painting

In [150]:
show_maps('../data/landscape/5.jpg', '../data/landscape_paintings/2.jpg', 20, True)